home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-03-20 | 5.8 KB | 221 lines | [TEXT/MMCC] |
- /*
- QD PICT To QD GX Picture.c
-
- This files demonstrates the use of the QuickDraw to QuickDraw GX translator. The translator
- will convert all QuickDraw objects to their equivalent GX objects, including PicComments. For
- complete details about the translator, please see the documentation. The translator is used
- by QD GX printing to convert all "old" QuickDraw objects to their QuickDraw GX equivalents
- during print time for non-QuickDraw GX based applications.
-
- When you want to draw the QuickDraw GX picture, click within the window.
-
- Enjoy,
-
- ...Luke
-
- >> Pete "Luke" Alexander
- >> Apple Computer, Developer Technical Support
-
- Notes:
- • This file requires the "graphics shell.c", "ColorLibrary.c", "TransformLibrary.c" to run.
-
- • This file prints the best in "landscape".
-
- ©1992 - 1994 Apple Computer, Inc.
- All rights reserved.
- */
-
- //#define MacintoshIncludes // This allows us to call QD's GXDrawPicture with out a conflict with GX
-
-
- #include <Types.h> // defines noErr
- #include <Errors.h>
- #include <QuickDraw.h>
- #include <Fonts.h>
- #include <Dialogs.h>
- #include <Memory.h>
- #include <Events.h>
- #include <FixMath.h>
- #include <Windows.h>
-
- #include <GXEnvironment.h>
- #include <GXPrinting.h>
- #include "GraphicsLibraries.h"
-
- #include "graphics shell.h"
-
-
- //
- // Set up the title and size of the window
- //
- Str255 gWindowTitle = "\p QuickDraw PICT (click for GX picture) ";
- Rect gWindowQDRect = {40, 10, 300, 400};
-
- //
- // Once the user have "clicked", this tells us to draw the QuickDraw GX version
- // of the converted QuickDraw PICT.
- //
- Boolean gClickState = false;
-
- //
- // gGraphicsHeapSize sets the size of the graphics gxHeap created by calling the GXNewGraphicsClient routine
- // in main () within graphics shell.c. You can determine the amount of graphics gxHeap required by using GraphicsBug.
- // With gGraphicsHeapSize set to 25k, I had 2 free blocks left in the graphics gxHeap. Sounds good to me.
- //
- long gGraphicsHeapSize = 25;
-
- gxShape gShape, gWindowRectangle;
-
-
-
- /*------ Protoypes local to this file -------------------------------------------------*/
-
- PicHandle CreateQDPicture(void);
-
-
- /*------ CreateQDPicture --------------------------------------------------------------*/
-
- PicHandle CreateQDPicture()
- {
- PicHandle myPict;
- Rect aRect;
- PenState *aPenStat;
- short theFontID;
-
- aPenStat = (PenState*) NewPtr(sizeof(PenState));
- GetPenState(aPenStat);
-
- aPenStat->pnSize.v = 2;
- aPenStat->pnSize.h = 1;
-
- //
- // Create a QuickDraw picture to be converted to a QuickDraw GX picture.
- //
- myPict = OpenPicture(&gWindowQDRect);
- {
- SetPenState(aPenStat); // Set the pen size to 1 gxWide x 2 high
- ClipRect(&gWindowQDRect);
-
- GetFNum("\pTimes", &theFontID);
- TextFont(theFontID);
- TextSize (27);
-
- MoveTo(120,80);
- DrawString("\pThis is only a test...");
-
- SetRect(&aRect,50,40,350,250);
- FrameRect(&aRect);
- MoveTo(350,250);
- LineTo(50,40);
- }
- ClosePicture();
-
- DrawPicture(myPict, &gWindowQDRect);
-
- DisposePtr((Ptr)aPenStat);
-
- return myPict;
- } // CreateQDPicture
-
-
- /*------ DoInitialization ---------------------------------------------------------------------------------*/
-
- void DoInitialization(aWindow)
- WindowPtr aWindow;
- {
- PicHandle myPict;
- OSErr anErr;
- Point patStretchPoint;
- gxRectangle fixedWindowBounds; /** bounding box of the window in local coordinates **/
-
- GXInitPrinting (); // We need to initialize printing because we are using the translator
-
- InitCommonColors();
-
- //
- // Get the bounds of the window, and create a gxRectangle that will fill the window
- //
- GXGetShapeBounds(gWindowBoundsShape, 0L, &fixedWindowBounds);
- gWindowRectangle = GXNewRectangle(&fixedWindowBounds);
- SetShapeCommonColor (gWindowRectangle ,gxWhite);
-
- SetPort (aWindow);
-
- myPict = CreateQDPicture();
-
- patStretchPoint.v = patStretchPoint.h = 1; // We do not want any stretching to occur
-
- //
- // Create a GX picture to hold the "translated" QuickDraw picture
- //
- gShape = GXNewShape (gxPictureType);
-
- //
- // Convert the QuickDraw picture - myPict to a GX picture
- //
- GXConvertPICTToShape(myPict,
- gxDefaultOptionsTranslation,
- &gWindowQDRect, &gWindowQDRect,
- patStretchPoint, gShape,
- 0);
-
- KillPicture(myPict);
- }
-
-
- /*------ DoDraw ---------------------------------------------------------------------------------------*/
-
- void DoDraw(aWindow)
- WindowPtr aWindow;
- {
- if (gClickState)
- GXDrawShape (gShape);
- }
-
-
- /*------ DoDispose -------------------------------------------------------------------------------------*/
-
- void DoDispose(aWindow)
- WindowPtr aWindow;
- {
- /**
- You should always dispose of your GX graphics objects before tossing your window. Why? It's generally good
- form and this approach guarantees that everything is disposed. If you had not disposed of everything, the
- call to DisposeWindow should dispose of the objects. If you are running the debugging version of the
- SecretGraphics init with notices set, you will receive a notice that you had not disposed of everything. You
- can turn notices on in this file by setting gDebugging = TRUE (above).
- **/
- GXDisposeShape(gWindowRectangle);
- GXDisposeShape(gShape);
- GXDisposeShape(gWindowBoundsShape);
- DisposeCommonColors();
- GXExitPrinting ();
- DisposeWindow(aWindow);
- }
-
-
-
- /*------ DoClick ---------------------------------------------------------------------------------------*/
-
- void DoClick( orgMouseLoc, theWindow )
- gxPoint orgMouseLoc;
- WindowPtr theWindow;
- {
- if (!gClickState) {
- SetShapeCommonColor ( gWindowBoundsShape, gxWhite );
- GXDrawShape ( gWindowBoundsShape );
- GXDrawShape ( gShape );
-
- SetWTitle( theWindow, "\p QuickDraw GX Picture" );
- gClickState = true;
- }
- }
-
-
- /*------ DoIdle ----------------------------------------------------------------------------------------*/
-
- void DoIdle(aWindow)
- WindowPtr aWindow;
- {
- }
-